/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/13 14:27
  *
  * @file       pd_timer_oc.h
  * @brief      Header file of TimerOC peripheral driver.
  *
  * @note       This file contains the TimerOC object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/13     Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_TIMER_OC_H
#define JLC_SKY_TIMER_OC_H

#include "pd_timer.h"
#include "pd_timer_ch.h"

struct TimerOCVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    Timer *timer;
    TimerCh *timerCh;

    uint32_t OCMode;
    uint32_t OCState;
    uint32_t OCPolarity;
    uint32_t CompareValue;

    uint32_t OCNState;
    uint32_t OCNPolarity;
    uint32_t OCIdleState;
    uint32_t OCNIdleState;

    // TimerOC virtual table
    struct TimerOCVtbl *vptr;
} TimerOC;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct TimerOCVtbl {
    void (*init)(const TimerOC *this);

    void (*set_ccr)(const TimerOC *this, uint32_t channel, uint32_t CompareValue);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void TimerOC_constructor(TimerOC *this, Timer *timer, TimerCh *timerCh, uint32_t CompareValue);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void TimerOC_init(const TimerOC *this) {
    this->vptr->init(this);
}

static inline void TimerOC_setCCR(const TimerOC *this, uint32_t channel, uint32_t CompareValue) {
    this->vptr->set_ccr(this, channel, CompareValue);
}
/**
 * @}
 */

#endif //JLC_SKY_TIMER_OC_H
